package com.zhiyou100.action01;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yang
 * @className Demo03
 * @packageName com.zhiyou100.action01
 * @Description TODO 设置 action 的返回值类型
 * @date 2020-08-21 14:53
 */
@Controller
@RequestMapping("/d3")
public class Demo03 {

    /**
     * 1、返回值类型是 String ，返回的是 跳转资源的路径
     *
     * @return String
     */
    @RequestMapping("/m1.action")
    public String method01() {
        return "test01/success";
    }


    /**
     * 2、 返回值类型是 ModelAdnView 设置跳转资源的路径 + request 域属性
     *
     * @return ModelAndView
     */
    @RequestMapping("/m2.action")
    public ModelAndView method02() {
        final ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("message", "modelAndView_message");
        modelAndView.setViewName("test01/success");
        return modelAndView;
    }

    /**
     * 3 返回值类型是void::设置跳转资源的路径+request域属性
     *
     * @param request  request
     * @param response response
     * @throws Exception Exception
     */
    @RequestMapping("/m3.action")
    public void method03(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println(request.getContextPath());
        response.sendRedirect(request.getContextPath() + "/test01/success.jsp");

    }


}
